cmake_minimum_required(VERSION 2.8)
project(luAPL)

if(WIN32)
  FIND_PACKAGE(Lua51 REQUIRED)
  include_directories(${CMAKE_SOURCE_DIR}/Aplus/wininc)
else(WIN32)
  FIND_PACKAGE(Threads)
endif(WIN32)

include_directories(${CMAKE_SOURCE_DIR}/Lua/inc)
include_directories(${CMAKE_SOURCE_DIR}/Aplus/asrc)

file(GLOB_RECURSE SRC "${CMAKE_SOURCE_DIR}/Lua/src/*.cpp")

link_directories(${CMAKE_BINARY_DIR}/Aplus)

if(MSVC)
  add_definitions(-D__VISUAL_STUDIO)
endif(MSVC)

IF(APPLE)
  SET(APP_TYPE MACOSX_BUNDLE)
  SET(CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS} "-bundle -undefined dynamic_lookup")
  add_executable(luAPL ${APP_TYPE} ${SRC})
ELSE(APPLE)
  add_library(luAPL SHARED ${SRC})
ENDIF(APPLE)

target_link_libraries (luAPL Aplus)

if(WIN32)
  target_link_libraries (luAPL ${LUA_LIBRARIES})
else(WIN32)
  target_link_libraries (luAPL ${CMAKE_THREAD_LIBS_INIT})
endif(WIN32)

IF(APPLE)
  install(FILES "${CMAKE_BINARY_DIR}/Lua/luAPL.app/Contents/MacOS/luAPL" DESTINATION scripts)
else(APPLE)
  install(TARGETS luAPL DESTINATION scripts)
endif(APPLE)
